#ifndef  _H_DB_ACCESS
#define _H_DB_ACCESS

#include <windows.h>
#include <mysql.h>
#include <string>
#include <memory>
#include <iostream>
#include <stdexcept>

namespace will {

	class DbAccess{
	
	public:	
		DbAccess(const std::string&,   //host
				const std::string&,		//username	
				const std::string&,		//passwd
				const std::string&,		//dbname
				const int &);			//port
		~DbAccess();
		int execute_query(const char*);
		//clear the result_set
		int clear_query(MYSQL_RES*);
		MYSQL_RES* get_result_set();

	private:
		MYSQL _m_handler;
	}; 

	//MYSQL ResultSet Iterator
	class ResultSetIterator{
	public:
		ResultSetIterator():_m_record(NULL){}
		explicit ResultSetIterator(MYSQL_RES* res);
		ResultSetIterator& operator=(const ResultSetIterator& rhs);

		ResultSetIterator& operator++();
		void operator++(int);
		MYSQL_ROW& operator*(){
			return _m_record;
		}
		bool operator==(const ResultSetIterator& rhs)const;
		bool operator!=(const ResultSetIterator& rhs) const;

	private:
		MYSQL_RES* _m_res;
		MYSQL_ROW _m_record;
	};
}

#endif

